package Year22_Month03.day10;

import java.util.HashMap;
import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            String[] arr = s.split("-");
            System.out.println(myfunc1(arr[0],arr[1]));
        }
    }

    public static String myfunc1(String s1,String s2){
        //利用hashmap的映射关系来进行后面的比较
        HashMap<String,Integer> myMap = new HashMap<>();
        myMap.put("A", 14);
        myMap.put("2", 15);
        myMap.put("3", 3);
        myMap.put("4", 4);
        myMap.put("5", 5);
        myMap.put("6", 6);
        myMap.put("7", 7);
        myMap.put("8", 8);
        myMap.put("9", 9);
        myMap.put("10", 10);
        myMap.put("J", 11);
        myMap.put("Q", 12);
        myMap.put("K", 13);
        myMap.put("joker", 16);
        myMap.put("JOKER", 17);
        //如果有双王那么我就不用比了
        if(s1.equals("joker JOKER") || s1.equals("JOKER joker")){
            return s1;
        }
        if(s2.equals("joker JOKER") || s2.equals("JOKER joker")){
            return s2;
        }

        String[] myarr1 = s1.split(" ");
        String[] myarr2 = s2.split(" ");
        int n1 = myMap.get(myarr1[0]);
        int n2 = myMap.get(myarr2[0]);
        if(myfunc2(s1) && myfunc2(s2)){
            return n1 > n2 ? s1 : s2;
        }else if(myfunc2(s1)){
            return s1;
        }else  if(myfunc2(s2)){
            return s2;
        }else if(myarr1.length == myarr2.length){
            return n1 > n2 ? s1 : s2;
        }else{
            return "ERROR";
        }
    }

    //这个方法主要是检验是否是相同的
    public static boolean myfunc2(String s){
        String[] arr = s.split(" ");//首先按照空格划分
        if(arr.length != 4){
            return false;
        }
        String myTmpS = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if(!arr[i].equals(myTmpS)){
                return false;
            }
        }
        return true;
    }
}
